package com.masterclient.app.modules.aftersale;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.utils.ScreenUtils;

/**
 * 作者：sean
 * 创建时间：2017/8/1 19:40
 * 功能说明：
 */

public class SetAliPayDialog extends Dialog implements View.OnClickListener{


    ImageView ivClose;
    EditText et_username,et_zfb_count;
    RelativeLayout rl_clear,rl_clear_zfb;
    TextView tv_submit;
    public SetAliPayDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_set_zifubao);
        findViewById(R.id.iv_close).setOnClickListener(this);
        et_username = (EditText) findViewById(R.id.et_username);
        findViewById(R.id.rl_clear).setOnClickListener(this);
        et_zfb_count = (EditText) findViewById(R.id.et_zfb_count);
        findViewById(R.id.rl_clear_zfb).setOnClickListener(this);
        findViewById(R.id.tv_submit).setOnClickListener(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        window.setWindowAnimations(R.style.bottomShow);
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.BOTTOM);
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    public void setAccount(String name,String account){
        et_username.setText(name);
        et_zfb_count.setText(account);
    }

    @Override
    protected void onStop() {
        hideSoftInput(et_username);
        super.onStop();
    }

    public void hideSoftInput(EditText et) {
        InputMethodManager inputManager = (InputMethodManager)et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(et.getWindowToken(), 0);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.rl_clear:
                et_username.setText("");
                break;
            case R.id.rl_clear_zfb:
                et_zfb_count.setText("");
                break;
            case R.id.tv_submit:
                String uname = et_username.getText().toString().trim();
                String account = et_zfb_count.getText().toString().trim();
                if(onSubmitListener!=null){
                    onSubmitListener.onSubmit(uname,account);
                }
                break;
        }
    }

    private OnSubmitListener onSubmitListener;

    public void setOnSubmitListener(OnSubmitListener onSubmitListener) {
        this.onSubmitListener = onSubmitListener;
    }

    public interface OnSubmitListener{
        public void onSubmit(String uname,String account);
    }
}
